<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>blmc_drivers: /workspace/software/workspace/src/catkin/hardware/blmc_drivers/include/blmc_drivers/utils/os_interface.hpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">blmc_drivers
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('os__interface_8hpp_source.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">os_interface.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="os__interface_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;</div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="preprocessor">#pragma once</span></div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;</div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="preprocessor">#ifdef __XENO__</span></div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="preprocessor">#include &lt;native/task.h&gt;</span></div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="preprocessor">#include &lt;native/timer.h&gt;</span></div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="preprocessor">#include &lt;native/mutex.h&gt;</span></div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="preprocessor">#include &lt;native/cond.h&gt;</span></div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="preprocessor">#include &lt;rtdk.h&gt;</span></div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="preprocessor">#include &lt;rtdm/rtcan.h&gt;</span></div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;</div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;<span class="preprocessor">#else</span></div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;<span class="preprocessor">#include &lt;stdio.h&gt;</span></div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;<span class="preprocessor">#include &lt;stdlib.h&gt;</span></div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;<span class="preprocessor">#include &lt;unistd.h&gt;</span></div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;<span class="preprocessor">#include &lt;stdint.h&gt;</span></div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;<span class="preprocessor">#include &lt;string.h&gt;</span></div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;<span class="preprocessor">#include &lt;net/if.h&gt;</span></div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;<span class="preprocessor">#include &lt;sys/types.h&gt;</span></div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;<span class="preprocessor">#include &lt;sys/socket.h&gt;</span></div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;<span class="preprocessor">#include &lt;sys/ioctl.h&gt;</span></div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;<span class="preprocessor">#include &lt;linux/can.h&gt;</span></div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;<span class="preprocessor">#include &lt;linux/can/raw.h&gt;</span></div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;<span class="preprocessor">#include &lt;limits.h&gt;</span></div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;<span class="preprocessor">#include &lt;real_time_tools/timer.hpp&gt;</span></div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;<span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;</div><div class="line"><a name="l00059"></a><span class="lineno"><a class="line" href="os__interface_8hpp.html#a8bc67ce447b2fa424a45f3e01162035f">   59</a></span>&#160;<span class="keyword">typedef</span> <span class="keyword">struct </span>can_frame <a class="code" href="os__interface_8hpp.html#a8bc67ce447b2fa424a45f3e01162035f">can_frame_t</a>;</div><div class="line"><a name="l00063"></a><span class="lineno"><a class="line" href="os__interface_8hpp.html#ab9491ad99890aa9ecf1785d1edd23d64">   63</a></span>&#160;<span class="keyword">typedef</span> canid_t <a class="code" href="os__interface_8hpp.html#ab9491ad99890aa9ecf1785d1edd23d64">can_id_t</a>;</div><div class="line"><a name="l00067"></a><span class="lineno"><a class="line" href="os__interface_8hpp.html#ad3b24c25feabadba465f8797d8c7fe27">   67</a></span>&#160;<span class="keyword">typedef</span> uint64_t <a class="code" href="os__interface_8hpp.html#ad3b24c25feabadba465f8797d8c7fe27">nanosecs_abs_t</a>;</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;</div><div class="line"><a name="l00072"></a><span class="lineno"><a class="line" href="os__interface_8hpp.html#a25df6b00e3fd8b8740896ecc5c337fdc">   72</a></span>&#160;<span class="preprocessor">#define rt_fprintf fprintf</span></div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;</div><div class="line"><a name="l00076"></a><span class="lineno"><a class="line" href="os__interface_8hpp.html#a1acf1ce04ab7fe3a5972c0618adcbbac">   76</a></span>&#160;<span class="preprocessor">#define rt_printf printf</span></div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;</div><div class="line"><a name="l00081"></a><span class="lineno"><a class="line" href="os__interface_8hpp.html#ac420926cbb955a79a41eba7cec1bc1c8">   81</a></span>&#160;<span class="preprocessor">#define rt_dev_socket socket</span></div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;</div><div class="line"><a name="l00085"></a><span class="lineno"><a class="line" href="os__interface_8hpp.html#a81e55d2bdf351cd53218a3085ba56955">   85</a></span>&#160;<span class="preprocessor">#define rt_dev_ioctl ioctl</span></div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;</div><div class="line"><a name="l00089"></a><span class="lineno"><a class="line" href="os__interface_8hpp.html#a7be59cefa5f5e5da067c04078f504aa6">   89</a></span>&#160;<span class="preprocessor">#define rt_dev_close close</span></div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;</div><div class="line"><a name="l00093"></a><span class="lineno"><a class="line" href="os__interface_8hpp.html#a80d28afb04b8db1e0192593ebcb4d07b">   93</a></span>&#160;<span class="preprocessor">#define rt_dev_setsockopt setsockopt</span></div><div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;</div><div class="line"><a name="l00097"></a><span class="lineno"><a class="line" href="os__interface_8hpp.html#a68219f584f63b92f4d23bd708140056d">   97</a></span>&#160;<span class="preprocessor">#define rt_dev_bind bind</span></div><div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;</div><div class="line"><a name="l00101"></a><span class="lineno"><a class="line" href="os__interface_8hpp.html#ab599460d70a4af2e3bcb07b395f13ad4">  101</a></span>&#160;<span class="preprocessor">#define rt_dev_recvmsg recvmsg</span></div><div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;</div><div class="line"><a name="l00105"></a><span class="lineno"><a class="line" href="os__interface_8hpp.html#ad9b081422ea995f98485f5545e20211d">  105</a></span>&#160;<span class="preprocessor">#define rt_dev_sendto sendto</span></div><div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;</div><div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;</div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;<span class="preprocessor">#include &lt;sstream&gt;</span></div><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;<span class="preprocessor">#include &lt;mutex&gt;</span></div><div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;<span class="preprocessor">#include &lt;condition_variable&gt;</span></div><div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;</div><div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;<span class="preprocessor">#include &lt;sys/mman.h&gt;</span></div><div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;</div><div class="line"><a name="l00123"></a><span class="lineno"><a class="line" href="namespaceosi.html">  123</a></span>&#160;<span class="keyword">namespace </span><a class="code" href="namespaceosi.html">osi</a></div><div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;{</div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;<span class="preprocessor">#ifdef __XENO__</span></div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;</div><div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;<span class="keyword">namespace </span>xenomai</div><div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;{</div><div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;<span class="keyword">class </span>mutex</div><div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;{</div><div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;<span class="keyword">public</span>:</div><div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;    RT_MUTEX rt_mutex_;</div><div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;</div><div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;    mutex()</div><div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;    {</div><div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;        rt_mutex_create(&amp;rt_mutex_, NULL);</div><div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;    }</div><div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;</div><div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;    <span class="keywordtype">void</span> lock()</div><div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;    {</div><div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;        rt_mutex_acquire(&amp;rt_mutex_, TM_INFINITE);</div><div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;    }</div><div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;</div><div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;    <span class="keywordtype">void</span> unlock()</div><div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;    {</div><div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;        rt_mutex_release(&amp;rt_mutex_);</div><div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;    }</div><div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;};</div><div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;</div><div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;<span class="keyword">class </span>condition_variable</div><div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;{</div><div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;<span class="keyword">public</span>:</div><div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;    RT_COND rt_condition_variable_;</div><div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;</div><div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;    condition_variable()</div><div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;    {</div><div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;        rt_cond_create(&amp;rt_condition_variable_, NULL);</div><div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;    }</div><div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;</div><div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;    <span class="keywordtype">void</span> wait(std::unique_lock&lt;mutex&gt; &amp;lock)</div><div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;    {</div><div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;        rt_cond_wait(&amp;rt_condition_variable_,</div><div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;                     &amp;lock.mutex()-&gt;rt_mutex_, TM_INFINITE);</div><div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;    }</div><div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;</div><div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;    <span class="keywordtype">void</span> notify_all()</div><div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;    {</div><div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;        rt_cond_broadcast(&amp;rt_condition_variable_);</div><div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;    }</div><div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;};</div><div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;} <span class="comment">// namespace xenomai</span></div><div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160;<span class="comment"></span><span class="keyword">typedef</span> xenomai::mutex <a class="code" href="namespaceosi.html#ac3d484da0f89f06e329d4b84d7459d9b">Mutex</a>;</div><div class="line"><a name="l00213"></a><span class="lineno">  213</span>&#160;</div><div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;<span class="keyword">typedef</span> xenomai::condition_variable <a class="code" href="namespaceosi.html#a31b1ce104b168554e4832b5d3b684073">ConditionVariable</a>;</div><div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;</div><div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;<span class="preprocessor">#else</span></div><div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;</div><div class="line"><a name="l00224"></a><span class="lineno"><a class="line" href="namespaceosi.html#ac3d484da0f89f06e329d4b84d7459d9b">  224</a></span>&#160;<span class="keyword">typedef</span> std::mutex <a class="code" href="namespaceosi.html#ac3d484da0f89f06e329d4b84d7459d9b">Mutex</a>;</div><div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;</div><div class="line"><a name="l00230"></a><span class="lineno"><a class="line" href="namespaceosi.html#a31b1ce104b168554e4832b5d3b684073">  230</a></span>&#160;<span class="keyword">typedef</span> std::condition_variable <a class="code" href="namespaceosi.html#a31b1ce104b168554e4832b5d3b684073">ConditionVariable</a>;</div><div class="line"><a name="l00231"></a><span class="lineno">  231</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;</div><div class="line"><a name="l00243"></a><span class="lineno"><a class="line" href="namespaceosi.html#a001686caee0f34611f14ab94c7303254">  243</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="namespaceosi.html#a001686caee0f34611f14ab94c7303254">send_to_can_device</a>(<span class="keywordtype">int</span> fd, <span class="keyword">const</span> <span class="keywordtype">void</span> *buf, <span class="keywordtype">size_t</span> len,</div><div class="line"><a name="l00244"></a><span class="lineno">  244</span>&#160;                               <span class="keywordtype">int</span> flags, <span class="keyword">const</span> <span class="keyword">struct</span> sockaddr *to,</div><div class="line"><a name="l00245"></a><span class="lineno">  245</span>&#160;                               socklen_t tolen)</div><div class="line"><a name="l00246"></a><span class="lineno">  246</span>&#160;{</div><div class="line"><a name="l00247"></a><span class="lineno">  247</span>&#160;    <span class="comment">// int ret = rt_dev_sendto(fd, buf, len, flags, to, tolen);</span></div><div class="line"><a name="l00248"></a><span class="lineno">  248</span>&#160;</div><div class="line"><a name="l00249"></a><span class="lineno">  249</span>&#160;    <span class="comment">// if (ret &lt; 0)</span></div><div class="line"><a name="l00250"></a><span class="lineno">  250</span>&#160;    <span class="comment">// {</span></div><div class="line"><a name="l00251"></a><span class="lineno">  251</span>&#160;    <span class="comment">//     std::ostringstream oss;</span></div><div class="line"><a name="l00252"></a><span class="lineno">  252</span>&#160;    <span class="comment">//     oss &lt;&lt; &quot;something went wrong with sending &quot;</span></div><div class="line"><a name="l00253"></a><span class="lineno">  253</span>&#160;    <span class="comment">//         &lt;&lt; &quot;CAN frame, error code: &quot;</span></div><div class="line"><a name="l00254"></a><span class="lineno">  254</span>&#160;    <span class="comment">//         &lt;&lt; ret &lt;&lt; &quot;, errno=&quot; &lt;&lt; errno &lt;&lt; std::endl;</span></div><div class="line"><a name="l00255"></a><span class="lineno">  255</span>&#160;    <span class="comment">//     throw std::runtime_error(oss.str());</span></div><div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160;    <span class="comment">// }</span></div><div class="line"><a name="l00257"></a><span class="lineno">  257</span>&#160;</div><div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; <span class="keyword">true</span>; i++)</div><div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;    {</div><div class="line"><a name="l00260"></a><span class="lineno">  260</span>&#160;        <span class="keywordtype">int</span> ret = <a class="code" href="os__interface_8hpp.html#ad9b081422ea995f98485f5545e20211d">rt_dev_sendto</a>(fd, buf, len, flags, to, tolen);</div><div class="line"><a name="l00261"></a><span class="lineno">  261</span>&#160;        <span class="keywordflow">if</span> (ret &gt;= 0)</div><div class="line"><a name="l00262"></a><span class="lineno">  262</span>&#160;        {</div><div class="line"><a name="l00263"></a><span class="lineno">  263</span>&#160;            <span class="keywordflow">if</span> (i &gt; 0)</div><div class="line"><a name="l00264"></a><span class="lineno">  264</span>&#160;            {</div><div class="line"><a name="l00265"></a><span class="lineno">  265</span>&#160;                std::cout &lt;&lt; <span class="stringliteral">&quot; Managed to send after &quot;</span></div><div class="line"><a name="l00266"></a><span class="lineno">  266</span>&#160;                          &lt;&lt; i &lt;&lt; <span class="stringliteral">&quot; attempts.&quot;</span> &lt;&lt; std::endl;</div><div class="line"><a name="l00267"></a><span class="lineno">  267</span>&#160;            }</div><div class="line"><a name="l00268"></a><span class="lineno">  268</span>&#160;            <span class="keywordflow">return</span>;</div><div class="line"><a name="l00269"></a><span class="lineno">  269</span>&#160;        }</div><div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;</div><div class="line"><a name="l00271"></a><span class="lineno">  271</span>&#160;        <span class="keywordflow">if</span> (i == 0)</div><div class="line"><a name="l00272"></a><span class="lineno">  272</span>&#160;        {</div><div class="line"><a name="l00273"></a><span class="lineno">  273</span>&#160;            std::cout &lt;&lt; <span class="stringliteral">&quot;WARNING: Something went wrong with sending &quot;</span></div><div class="line"><a name="l00274"></a><span class="lineno">  274</span>&#160;                      &lt;&lt; <span class="stringliteral">&quot;CAN frame, error code: &quot;</span></div><div class="line"><a name="l00275"></a><span class="lineno">  275</span>&#160;                      &lt;&lt; ret &lt;&lt; <span class="stringliteral">&quot;, errno: &quot;</span> &lt;&lt; errno &lt;&lt; <span class="stringliteral">&quot;. Possibly you have &quot;</span></div><div class="line"><a name="l00276"></a><span class="lineno">  276</span>&#160;                      &lt;&lt; <span class="stringliteral">&quot;been attempting to send at a rate which is too &quot;</span></div><div class="line"><a name="l00277"></a><span class="lineno">  277</span>&#160;                      &lt;&lt; <span class="stringliteral">&quot;high. We keep trying&quot;</span> &lt;&lt; std::flush;</div><div class="line"><a name="l00278"></a><span class="lineno">  278</span>&#160;        }</div><div class="line"><a name="l00279"></a><span class="lineno">  279</span>&#160;        <span class="keywordflow">else</span></div><div class="line"><a name="l00280"></a><span class="lineno">  280</span>&#160;        {</div><div class="line"><a name="l00281"></a><span class="lineno">  281</span>&#160;            std::cout &lt;&lt; <span class="stringliteral">&quot;.&quot;</span> &lt;&lt; std::flush;</div><div class="line"><a name="l00282"></a><span class="lineno">  282</span>&#160;        }</div><div class="line"><a name="l00283"></a><span class="lineno">  283</span>&#160;</div><div class="line"><a name="l00284"></a><span class="lineno">  284</span>&#160;        <a class="code" href="namespaceosi.html#a499cdf6336a907d1327044b0f595f3a9">real_time_tools::Timer::sleep_ms</a>(0.1);</div><div class="line"><a name="l00285"></a><span class="lineno">  285</span>&#160;    }</div><div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160;}</div><div class="line"><a name="l00287"></a><span class="lineno">  287</span>&#160;</div><div class="line"><a name="l00294"></a><span class="lineno"><a class="line" href="namespaceosi.html#a92dc20de3b4933a10f24c98cecf2568b">  294</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="namespaceosi.html#a92dc20de3b4933a10f24c98cecf2568b">close_can_device</a>(<span class="keywordtype">int</span> socket)</div><div class="line"><a name="l00295"></a><span class="lineno">  295</span>&#160;{</div><div class="line"><a name="l00296"></a><span class="lineno">  296</span>&#160;    <span class="keywordtype">int</span> ret = <a class="code" href="os__interface_8hpp.html#a7be59cefa5f5e5da067c04078f504aa6">rt_dev_close</a>(socket);</div><div class="line"><a name="l00297"></a><span class="lineno">  297</span>&#160;    <span class="keywordflow">if</span> (ret)</div><div class="line"><a name="l00298"></a><span class="lineno">  298</span>&#160;    {</div><div class="line"><a name="l00299"></a><span class="lineno">  299</span>&#160;        <a class="code" href="os__interface_8hpp.html#a25df6b00e3fd8b8740896ecc5c337fdc">rt_fprintf</a>(stderr, <span class="stringliteral">&quot;rt_dev_close: %s\n&quot;</span>, strerror(-ret));</div><div class="line"><a name="l00300"></a><span class="lineno">  300</span>&#160;        exit(-1);</div><div class="line"><a name="l00301"></a><span class="lineno">  301</span>&#160;    }</div><div class="line"><a name="l00302"></a><span class="lineno">  302</span>&#160;}</div><div class="line"><a name="l00303"></a><span class="lineno">  303</span>&#160;</div><div class="line"><a name="l00312"></a><span class="lineno"><a class="line" href="namespaceosi.html#a244466c0afc9ae9fe059cee665fb0603">  312</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="namespaceosi.html#a244466c0afc9ae9fe059cee665fb0603">receive_message_from_can_device</a>(<span class="keywordtype">int</span> fd, <span class="keyword">struct</span> msghdr *msg, <span class="keywordtype">int</span> flags)</div><div class="line"><a name="l00313"></a><span class="lineno">  313</span>&#160;{</div><div class="line"><a name="l00314"></a><span class="lineno">  314</span>&#160;    <span class="keywordtype">int</span> ret = <a class="code" href="os__interface_8hpp.html#ab599460d70a4af2e3bcb07b395f13ad4">rt_dev_recvmsg</a>(fd, msg, flags);</div><div class="line"><a name="l00315"></a><span class="lineno">  315</span>&#160;    <span class="keywordflow">if</span> (ret &lt; 0)</div><div class="line"><a name="l00316"></a><span class="lineno">  316</span>&#160;    {</div><div class="line"><a name="l00317"></a><span class="lineno">  317</span>&#160;        std::ostringstream oss;</div><div class="line"><a name="l00318"></a><span class="lineno">  318</span>&#160;        oss &lt;&lt; <span class="stringliteral">&quot;something went wrong with receiving &quot;</span></div><div class="line"><a name="l00319"></a><span class="lineno">  319</span>&#160;            &lt;&lt; <span class="stringliteral">&quot;CAN frame, error code: &quot;</span></div><div class="line"><a name="l00320"></a><span class="lineno">  320</span>&#160;            &lt;&lt; ret &lt;&lt; <span class="stringliteral">&quot;, errno=&quot;</span> &lt;&lt; errno &lt;&lt; std::endl;</div><div class="line"><a name="l00321"></a><span class="lineno">  321</span>&#160;        <span class="keywordflow">throw</span> std::runtime_error(oss.str());</div><div class="line"><a name="l00322"></a><span class="lineno">  322</span>&#160;    }</div><div class="line"><a name="l00323"></a><span class="lineno">  323</span>&#160;}</div><div class="line"><a name="l00324"></a><span class="lineno">  324</span>&#160;</div><div class="line"><a name="l00329"></a><span class="lineno"><a class="line" href="namespaceosi.html#a48e36c862c77befc86f53140722c3f43">  329</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="namespaceosi.html#a48e36c862c77befc86f53140722c3f43">initialize_realtime_printing</a>()</div><div class="line"><a name="l00330"></a><span class="lineno">  330</span>&#160;{</div><div class="line"><a name="l00331"></a><span class="lineno">  331</span>&#160;<span class="preprocessor">#ifdef __XENO__</span></div><div class="line"><a name="l00332"></a><span class="lineno">  332</span>&#160;    rt_print_auto_init(1);</div><div class="line"><a name="l00333"></a><span class="lineno">  333</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00334"></a><span class="lineno">  334</span>&#160;}</div><div class="line"><a name="l00335"></a><span class="lineno">  335</span>&#160;</div><div class="line"><a name="l00341"></a><span class="lineno"><a class="line" href="namespaceosi.html#a499cdf6336a907d1327044b0f595f3a9">  341</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="namespaceosi.html#a499cdf6336a907d1327044b0f595f3a9">sleep_ms</a>(<span class="keyword">const</span> <span class="keywordtype">double</span> &amp;sleep_time_ms)</div><div class="line"><a name="l00342"></a><span class="lineno">  342</span>&#160;{</div><div class="line"><a name="l00343"></a><span class="lineno">  343</span>&#160;<span class="preprocessor">#ifdef __XENO__</span></div><div class="line"><a name="l00344"></a><span class="lineno">  344</span>&#160;    rt_task_sleep(<span class="keywordtype">int</span>(sleep_time_ms * 1000000.));</div><div class="line"><a name="l00345"></a><span class="lineno">  345</span>&#160;<span class="preprocessor">#else</span></div><div class="line"><a name="l00346"></a><span class="lineno">  346</span>&#160;    usleep(sleep_time_ms * 1000.); <span class="comment">// nano_sleep</span></div><div class="line"><a name="l00347"></a><span class="lineno">  347</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00348"></a><span class="lineno">  348</span>&#160;}</div><div class="line"><a name="l00349"></a><span class="lineno">  349</span>&#160;</div><div class="line"><a name="l00356"></a><span class="lineno"><a class="line" href="namespaceosi.html#a2409ab591c4f78d9a8bcfbbe38df9429">  356</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">double</span> <a class="code" href="namespaceosi.html#a2409ab591c4f78d9a8bcfbbe38df9429">get_current_time_ms</a>()</div><div class="line"><a name="l00357"></a><span class="lineno">  357</span>&#160;{</div><div class="line"><a name="l00358"></a><span class="lineno">  358</span>&#160;<span class="preprocessor">#ifdef __XENO__</span></div><div class="line"><a name="l00359"></a><span class="lineno">  359</span>&#160;    <span class="keywordflow">return</span> double(rt_timer_read()) / 1000000.;</div><div class="line"><a name="l00360"></a><span class="lineno">  360</span>&#160;<span class="preprocessor">#else</span></div><div class="line"><a name="l00361"></a><span class="lineno">  361</span>&#160;    <span class="keyword">struct </span>timespec now;</div><div class="line"><a name="l00362"></a><span class="lineno">  362</span>&#160;    clock_gettime(CLOCK_REALTIME, &amp;now);</div><div class="line"><a name="l00363"></a><span class="lineno">  363</span>&#160;    <span class="keywordtype">double</span> current_time_ms = (double)(now.tv_sec * 1e3) + (now.tv_nsec / 1e6);</div><div class="line"><a name="l00364"></a><span class="lineno">  364</span>&#160;</div><div class="line"><a name="l00365"></a><span class="lineno">  365</span>&#160;    <span class="keywordflow">return</span> current_time_ms;</div><div class="line"><a name="l00366"></a><span class="lineno">  366</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00367"></a><span class="lineno">  367</span>&#160;}</div><div class="line"><a name="l00368"></a><span class="lineno">  368</span>&#160;</div><div class="line"><a name="l00372"></a><span class="lineno"><a class="line" href="namespaceosi.html#af6772d4aea95e99bc2bd0aabc557a20e">  372</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="namespaceosi.html#af6772d4aea95e99bc2bd0aabc557a20e">make_this_thread_realtime</a>()</div><div class="line"><a name="l00373"></a><span class="lineno">  373</span>&#160;{</div><div class="line"><a name="l00374"></a><span class="lineno">  374</span>&#160;<span class="preprocessor">#ifdef __XENO__</span></div><div class="line"><a name="l00375"></a><span class="lineno">  375</span>&#160;</div><div class="line"><a name="l00376"></a><span class="lineno">  376</span>&#160;    rt_task_shadow(NULL, NULL, 0, 0);</div><div class="line"><a name="l00377"></a><span class="lineno">  377</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00378"></a><span class="lineno">  378</span>&#160;}</div><div class="line"><a name="l00379"></a><span class="lineno">  379</span>&#160;</div><div class="line"><a name="l00380"></a><span class="lineno">  380</span>&#160;} <span class="comment">// namespace osi</span></div><div class="ttc" id="namespaceosi_html_ac3d484da0f89f06e329d4b84d7459d9b"><div class="ttname"><a href="namespaceosi.html#ac3d484da0f89f06e329d4b84d7459d9b">osi::Mutex</a></div><div class="ttdeci">std::mutex Mutex</div><div class="ttdoc">Wrapper around the posix specific Mutex implementation. </div><div class="ttdef"><b>Definition:</b> os_interface.hpp:224</div></div>
<div class="ttc" id="os__interface_8hpp_html_a8bc67ce447b2fa424a45f3e01162035f"><div class="ttname"><a href="os__interface_8hpp.html#a8bc67ce447b2fa424a45f3e01162035f">can_frame_t</a></div><div class="ttdeci">struct can_frame can_frame_t</div><div class="ttdoc">xeno specific include </div><div class="ttdef"><b>Definition:</b> os_interface.hpp:59</div></div>
<div class="ttc" id="namespaceosi_html_af6772d4aea95e99bc2bd0aabc557a20e"><div class="ttname"><a href="namespaceosi.html#af6772d4aea95e99bc2bd0aabc557a20e">osi::make_this_thread_realtime</a></div><div class="ttdeci">void make_this_thread_realtime()</div><div class="ttdoc">This methd is requiered in xenomai to create a real time thread. </div><div class="ttdef"><b>Definition:</b> os_interface.hpp:372</div></div>
<div class="ttc" id="namespaceosi_html_a499cdf6336a907d1327044b0f595f3a9"><div class="ttname"><a href="namespaceosi.html#a499cdf6336a907d1327044b0f595f3a9">osi::sleep_ms</a></div><div class="ttdeci">void sleep_ms(const double &amp;sleep_time_ms)</div><div class="ttdoc">This function uses eather the xenomai API or the posix one. </div><div class="ttdef"><b>Definition:</b> os_interface.hpp:341</div></div>
<div class="ttc" id="os__interface_8hpp_html_ab9491ad99890aa9ecf1785d1edd23d64"><div class="ttname"><a href="os__interface_8hpp.html#ab9491ad99890aa9ecf1785d1edd23d64">can_id_t</a></div><div class="ttdeci">canid_t can_id_t</div><div class="ttdoc">Create a common type_def to wrap xenomai and posix. </div><div class="ttdef"><b>Definition:</b> os_interface.hpp:63</div></div>
<div class="ttc" id="namespaceosi_html_a2409ab591c4f78d9a8bcfbbe38df9429"><div class="ttname"><a href="namespaceosi.html#a2409ab591c4f78d9a8bcfbbe38df9429">osi::get_current_time_ms</a></div><div class="ttdeci">double get_current_time_ms()</div><div class="ttdoc">Get the current time in millisecond. </div><div class="ttdef"><b>Definition:</b> os_interface.hpp:356</div></div>
<div class="ttc" id="os__interface_8hpp_html_a25df6b00e3fd8b8740896ecc5c337fdc"><div class="ttname"><a href="os__interface_8hpp.html#a25df6b00e3fd8b8740896ecc5c337fdc">rt_fprintf</a></div><div class="ttdeci">#define rt_fprintf</div><div class="ttdoc">Create a common type_def to wrap xenomai and posix. </div><div class="ttdef"><b>Definition:</b> os_interface.hpp:72</div></div>
<div class="ttc" id="os__interface_8hpp_html_a7be59cefa5f5e5da067c04078f504aa6"><div class="ttname"><a href="os__interface_8hpp.html#a7be59cefa5f5e5da067c04078f504aa6">rt_dev_close</a></div><div class="ttdeci">#define rt_dev_close</div><div class="ttdoc">Create a common type_def to wrap xenomai and posix. </div><div class="ttdef"><b>Definition:</b> os_interface.hpp:89</div></div>
<div class="ttc" id="namespaceosi_html"><div class="ttname"><a href="namespaceosi.html">osi</a></div><div class="ttdoc">Common include. </div><div class="ttdef"><b>Definition:</b> os_interface.hpp:123</div></div>
<div class="ttc" id="namespaceosi_html_a31b1ce104b168554e4832b5d3b684073"><div class="ttname"><a href="namespaceosi.html#a31b1ce104b168554e4832b5d3b684073">osi::ConditionVariable</a></div><div class="ttdeci">std::condition_variable ConditionVariable</div><div class="ttdoc">Wrapper around the posix specific ConditionVariable implementation. </div><div class="ttdef"><b>Definition:</b> os_interface.hpp:230</div></div>
<div class="ttc" id="namespaceosi_html_a92dc20de3b4933a10f24c98cecf2568b"><div class="ttname"><a href="namespaceosi.html#a92dc20de3b4933a10f24c98cecf2568b">osi::close_can_device</a></div><div class="ttdeci">void close_can_device(int socket)</div><div class="ttdoc">This function is closing a socket on the Can device. </div><div class="ttdef"><b>Definition:</b> os_interface.hpp:294</div></div>
<div class="ttc" id="os__interface_8hpp_html_ab599460d70a4af2e3bcb07b395f13ad4"><div class="ttname"><a href="os__interface_8hpp.html#ab599460d70a4af2e3bcb07b395f13ad4">rt_dev_recvmsg</a></div><div class="ttdeci">#define rt_dev_recvmsg</div><div class="ttdoc">Create a common type_def to wrap xenomai and posix. </div><div class="ttdef"><b>Definition:</b> os_interface.hpp:101</div></div>
<div class="ttc" id="os__interface_8hpp_html_ad9b081422ea995f98485f5545e20211d"><div class="ttname"><a href="os__interface_8hpp.html#ad9b081422ea995f98485f5545e20211d">rt_dev_sendto</a></div><div class="ttdeci">#define rt_dev_sendto</div><div class="ttdoc">Create a common type_def to wrap xenomai and posix. </div><div class="ttdef"><b>Definition:</b> os_interface.hpp:105</div></div>
<div class="ttc" id="os__interface_8hpp_html_ad3b24c25feabadba465f8797d8c7fe27"><div class="ttname"><a href="os__interface_8hpp.html#ad3b24c25feabadba465f8797d8c7fe27">nanosecs_abs_t</a></div><div class="ttdeci">uint64_t nanosecs_abs_t</div><div class="ttdoc">Create a common type_def to wrap xenomai and posix. </div><div class="ttdef"><b>Definition:</b> os_interface.hpp:67</div></div>
<div class="ttc" id="namespaceosi_html_a001686caee0f34611f14ab94c7303254"><div class="ttname"><a href="namespaceosi.html#a001686caee0f34611f14ab94c7303254">osi::send_to_can_device</a></div><div class="ttdeci">void send_to_can_device(int fd, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen)</div><div class="ttdoc">Use the osi workspace API to communicate with the can bus. </div><div class="ttdef"><b>Definition:</b> os_interface.hpp:243</div></div>
<div class="ttc" id="namespaceosi_html_a244466c0afc9ae9fe059cee665fb0603"><div class="ttname"><a href="namespaceosi.html#a244466c0afc9ae9fe059cee665fb0603">osi::receive_message_from_can_device</a></div><div class="ttdeci">void receive_message_from_can_device(int fd, struct msghdr *msg, int flags)</div><div class="ttdoc">Poll? a message from the CAN device. </div><div class="ttdef"><b>Definition:</b> os_interface.hpp:312</div></div>
<div class="ttc" id="namespaceosi_html_a48e36c862c77befc86f53140722c3f43"><div class="ttname"><a href="namespaceosi.html#a48e36c862c77befc86f53140722c3f43">osi::initialize_realtime_printing</a></div><div class="ttdeci">void initialize_realtime_printing()</div><div class="ttdoc">This function is needed in xenomai to initialize the real time console display of text...</div><div class="ttdef"><b>Definition:</b> os_interface.hpp:329</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_80e6cdd9bbc895bd262b4f65e652822c.html">catkin</a></li><li class="navelem"><a class="el" href="dir_dace45749abc688185d44e8b166728a5.html">hardware</a></li><li class="navelem"><a class="el" href="dir_87d2711f33d814f4f77c208b3c1f3ba9.html">blmc_drivers</a></li><li class="navelem"><a class="el" href="dir_816dc94020a36d1af25b1f5614889f22.html">include</a></li><li class="navelem"><a class="el" href="dir_a56b819f7914f14382554b99ca83f1d8.html">blmc_drivers</a></li><li class="navelem"><a class="el" href="dir_07866751b7539cab91579191567dedd5.html">utils</a></li><li class="navelem"><a class="el" href="os__interface_8hpp.html">os_interface.hpp</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
